package model;

import java.util.Collection;
import java.util.LinkedHashSet;

/**
 * Credit 
 * 
 * @author orlin
 */
public class Credit {

	public static final String AND = ",";

	private Album album;
	private String role;
	private String tracks;
	private Collection<Artist> artists = new LinkedHashSet<Artist>();

	public Credit() {
	}

	public Credit(Album album, String role, String tracks, Collection<Artist> artists) {
		this.album = album;
		this.role = role;
		this.tracks = tracks;
		setArtists(artists);
	}

	public Album getAlbum() {
		return album;
	}
	public void setAlbum(Album album) {
		this.album = album;
	}
	public String getRole() {
		return role;
	}
	public void setRole(String role) {
		this.role = role;
	}
	public String getTracks() {
		return tracks;
	}
	public void setTracks(String tracks) {
		this.tracks = tracks;
	}
	public String getArtist() {
		StringBuffer result = new StringBuffer();
		for (Artist artist: artists) {
			if (result.length() != 0) {
				result.append(AND);
				result.append(" ");
			}
			result.append(artist.getName());
		}
		return result.toString();
	}
	public Collection<Artist> getArtists() {
		return artists;
	}
	public void setArtists(Collection<Artist> artists) {
		this.artists.clear();
		if (artists != null) {
			this.artists.addAll(artists);
		}
	}
	public void addArtist(Artist artist) {
		artists.add(artist);
	}

	@Override
	public String toString() {
		StringBuffer line = new StringBuffer();
		line.append("CreditDto [album:");
//		line.append(album);
		line.append(", role:");
		line.append(role);
		line.append(", artists:");
		line.append(artists);
		line.append(", tracks:");
		line.append(tracks);
		line.append("]");
		return line.toString();
	}
}
